package com.qmhl.toolposition.utils

import com.google.gson.FieldNamingPolicy
import com.google.gson.Gson
import com.google.gson.GsonBuilder

object JSONUtil {


    fun createGson(): Gson {
        val gsonBuilder = GsonBuilder()
        //设置驼峰下划线
//        gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
        return gsonBuilder.create()
    }


    fun toJSON(data: Any): String {
        return createGson().toJson(data)
    }

    /**
     * 将json转为对象
     * **/
    fun <T> fromJSON(data: String, clazz: Class<T>): T {
        return createGson().fromJson(data, clazz)
    }


}